<template>
  <basic-container>
    <el-form :inline="true" :model="query" class="demo-form-inline">
      <el-row>
        <el-form-item label="项目名称:">
          <el-input v-model="query.projectName" clearable placeholder="项目名称"></el-input>
        </el-form-item>
        <el-form-item label="项目类别:">
          <el-select v-model="query.isEnd" placeholder="请选择">
            <el-option :label=" '审定项目' " :value="true"></el-option>
            <el-option :label=" '送审项目' " :value="false"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">
          <div class="block">
            <el-date-picker
              placement="bottom-start"
              v-model="query.timeData"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']">
            </el-date-picker>
          </div>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="onSearch" :loading="loading">搜索
          </el-button>
          <el-button size="small" icon="el-icon-delete" @click="searchReset" :loading="loading">清空</el-button>
        </el-form-item>
      </el-row>
    </el-form>
    <div class="btn-operate">
      <el-button
        v-if="permissions.engineering_import_export"
        class="filter-item"
        plain
        type="primary"
        size="small"
        icon="el-icon-download"
        @click="exportExcel"
      >导出
      </el-button>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column prop="projectName" label="项目名称">
      </el-table-column>
      <el-table-column prop="developerName" label="建设单位">
      </el-table-column>
      <el-table-column prop="constructionUnitName" label="施工单位">
      </el-table-column>
      <el-table-column prop="assistCompanyName" label="协审单位">
      </el-table-column>
      <el-table-column prop="submissionAmount" label="送审金额">
      </el-table-column>
      <el-table-column prop="approveStartTime" label="送审时间">
      </el-table-column>
      <el-table-column prop="verifiedAmount" label="审定金额">
      </el-table-column>
      <el-table-column prop="approveEndTime" label="审定时间">
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page="page.currentPage"
        :page-sizes="[10, 20, 30, 40 ,50 ,100]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </div>
  </basic-container>
</template>

<script>
import {fetchProjectSummaryList} from "@/api/adis/report/reportFinal";
import {mapGetters} from "vuex";

export default {
  data() {
    return {
      tableData: [],
      query:{},
      page:[
        {
          total: 1,
          currentPage: 10
        }
      ],
    }
  },
  created() {
    this.onLoad(this.page);
  },
  computed:{
    ...mapGetters(["permissions"])
  },
  methods: {
    onSearch(){
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.page.current = 1;
      this.onLoad(this.page)
    },
    sizeChange(size) {
      this.page.size = size;
      this.onLoad(this.page);
    },
    currentChange(current) {
      this.page.current = current;
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      if (this.query.timeData){
        // 将 ISO 8601 格式的字符串转换为 Date 对象
        const beginTimeDate = new Date(this.query.timeData[0]);
        const endTimeDate = new Date(this.query.timeData[1]);

        // 格式化 Date 对象为 YYYY-MM-DD HH:mm:ss 格式
        this.query.beginTime = beginTimeDate.toISOString().slice(0, 19).replace('T', ' ');
        this.query.endTime = endTimeDate.toISOString().slice(0, 19).replace('T', ' ');
      }
      fetchProjectSummaryList(Object.assign(params, this.query, page)).then(res => {
        this.loading = false;
        const data = res.data.data;
        this.page.total = data.total;
        this.tableData = data.records;
      }, () => {
        this.loading = false;
      });
    },
    exportExcel(params = {}) {
      if (this.query.timeData){
        // 将 ISO 8601 格式的字符串转换为 Date 对象
        const beginTimeDate = new Date(this.query.timeData[0]);
        const endTimeDate = new Date(this.query.timeData[1]);

        // 格式化 Date 对象为 YYYY-MM-DD HH:mm:ss 格式
        this.query.beginTime = beginTimeDate.toISOString().slice(0, 19).replace('T', ' ');
        this.query.endTime = endTimeDate.toISOString().slice(0, 19).replace('T', ' ');
      }
      this.downBlobFile("/exam/auditComparison/export",Object.assign(params, this.query), "工程数据汇总表.xlsx");
    }
  }
}
</script>
